import JWT from 'jsonwebtoken';

import { useConfig } from '../config';

const signature = (data: any): string => {
  return JWT.sign(data, useConfig().jwt.secret, { expiresIn: useConfig().jwt.expires });
};
const verify = (token: string) => {
  try {
    const decoded = JWT.verify(token, useConfig().jwt.secret);
    return {
      admin: decoded,
      error: null,
    };
  } catch (e) {
    return {
      admin: null,
      error: e,
    };
  }
};
export { signature, verify };
